﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Windows.Media.Animation;

namespace CustomerUI
{
    /// <summary>
    /// Interaction logic for UserInfo.xaml
    /// </summary>
    public partial class UserInfo : UserControl
    {
        public static DependencyProperty UsernameProperty = DependencyProperty.Register("Username", typeof(string), typeof(UserInfo));
        public UserInfo()
        {
            InitializeComponent();
            MainWindow.customer.Messenger.Register<TinyCinema.Bussiness.Customer.Message.SetCustomerOK>(this, (s) =>
                {
                    (App.Current.MainWindow as MainWindow).blurEffect.Radius = 10;
                    (new TradeLog()).ShowDialog();
                });
        }
        
        public string Username
        {
            get { return (string)GetValue(UsernameProperty); }
            set { SetValue(UsernameProperty, value); }
        }

        bool isExpanded = false;
        private void btnUsername_Click(object sender, RoutedEventArgs e)
        {
            if (!isExpanded)
            {
                ((Storyboard)FindResource("triggerExpand")).Begin();
                isExpanded = true;                
                Panel.SetZIndex(this, Panel.GetZIndex(this)+2);
            }
            else ViewUnexpand();
        }

        private void UserControl_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Escape)
            {
                ViewUnexpand();
            }
        }
        public void ViewUnexpand()
        {
            if (isExpanded)
            {
                ((Storyboard)FindResource("triggerExpanded")).Begin();
                isExpanded = false;
                Panel.SetZIndex(this, 0);
            }
        }

        private void grdRoot_MouseDown(object sender, MouseButtonEventArgs e)
        {
            ViewUnexpand();
        }

        private void DoubleAnimationContent_Completed(object sender, EventArgs e)
        {
            bdrContent.Visibility = Visibility.Hidden;
        }

        private void ChangePassword(object sender, RoutedEventArgs e)
        {
            (App.Current.MainWindow as MainWindow).blurEffect.Radius = 10;
            (new ChangePassword()).ShowDialog();
        }
    }
}
